<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"  xmlns:f="http://java.sun.com/jsf/core" xmlns:c="http://java.sun.com/jsp/jstl/core">
    <h:head>
        <title>Provisioning: Network Browser</title>
    </h:head>
    <h:body>
        <div style="text-align: center;">
            <h:panelGroup rendered="#{userSessionBean.loggedIn}">
                <p:panel id="selectRouter" toggleable="true" toggleSpeed="500" header="Current Router" >  
                    <h:form>
                        <h:selectOneMenu value="#{routerExplorerBean.currentRouter}">
                            <f:converter converterId="data.RouterBeanConverter" />
                            <f:selectItem itemLabel="Select Router" itemValue="" />  
                            <f:selectItems value="#{routerExplorerBean.routerSelectItems}"/>
                            <f:ajax event="change" render=":navigation" execute="@this" immediate="true"/>
                        </h:selectOneMenu>
                        <h:commandButton value="Go!" type="submit"/>
                        <h:link outcome="welcome?faces-redirect=true" value="Return to Dashboard"/>
                    </h:form>
                </p:panel>
                <p:panel id="navigation" toggleable="true" toggleSpeed="500" header="Available Links" >  
                    <h:panelGroup rendered="#{routerExplorerBean.currentRouter eq null}">
                        Select router
                    </h:panelGroup> 
                    <h:panelGroup rendered="#{not (routerExplorerBean.currentRouter eq null)}">
                        <div style="text-align: left;">
                            <strong>Router ID:</strong> #{routerExplorerBean.currentRouter.id}<br/>
                            <strong>Router Name:</strong> #{routerExplorerBean.currentRouter.name}
                        </div>
                        <h:form>
                            <p:dataTable var="link" value="#{routerExplorerBean.currentRouter.listLinks()}" paginator="true" rows="10" rowKey="#{link.id}" paginatorAlwaysVisible="false"
                                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" 
                                     rowsPerPageTemplate="10,20,50" >  
                            <p:column>  
                                <f:facet name="header">  
                                    Link ID 
                                </f:facet>  
                                <h:outputText value="#{link.id}" />  
                            </p:column>
                            
                            <p:column>  
                                <f:facet name="header">  
                                    Link Title
                                </f:facet>  
                                <h:outputText value="#{link.title}" />  
                            </p:column>    
                                
                            <p:column>  
                                <f:facet name="header">  
                                    Total Bandwidth  
                                </f:facet>  
                                <h:outputText value="#{link.bandwidth} kbytes/s" />  
                            </p:column>  
                          
                            <p:column>  
                                <f:facet name="header">  
                                    Current Bandwidth 
                                </f:facet>  
                                <h:outputText value="#{link.currentBandwidth} kbytes/s" />  
                            </p:column>  
                            
                            <p:column>  
                                <f:facet name="header">  
                                    Reference 
                                </f:facet>  
                                <div style="font-size: 14px;">
                                    [#{(link.router1.id == routerExplorerBean.currentRouter.id) ? link.router2.id : link.router1.id}] 
                                    <h:commandLink action="#{routerExplorerBean.changeRouter((link.router1.id == routerExplorerBean.currentRouter.id) ? link.router2 : link.router1)}" value="#{(link.router1.id == routerExplorerBean.currentRouter.id) ? link.router2.name : link.router1.name}"/>
                                </div>
                            </p:column>  
                        </p:dataTable>
                    </h:form>
                    </h:panelGroup>
                </p:panel>
            </h:panelGroup>
            <h:panelGroup rendered="#{!userSessionBean.loggedIn}">
                You have not got permission for this operation. Please, <h:link value="sign in" outcome="login?faces-redirect=true"/>.
            </h:panelGroup>
        </div>
    </h:body>
</html>
